package com.kgcx.common.listener;

import com.kgcx.common.utils.CollectionUtils;
import com.kgcx.common.utils.FileUtils;
import com.kgcx.common.utils.SmsUtils;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 吴刚林
 * @date 2017/11/26
 */
@Component
public class ApplicationStartUp implements ApplicationRunner {

    private static List<Fun> runFunction = new ArrayList<>();

    @Override
    public void run(ApplicationArguments args) {
        if (CollectionUtils.isNotEmpty(runFunction)) {
            runFunction.forEach(Fun::dosometing);
        }
        FileUtils.initClient();
        SmsUtils.initClient();
    }

    public static void addFunction(Fun fun) {
        runFunction.add(fun);
    }

    @FunctionalInterface
    public interface Fun {
        void dosometing();
    }
}
